package com.itr.kbm.dao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.itr.kbm.dao.ListKopegDao;
import com.itr.kbm.model.Employee;
import com.itr.kbm.model.ListKopeg;

@Repository
public class ListKopegDaoImpl extends AbstractDaoImpl<ListKopeg, Integer> implements ListKopegDao {
	
    protected ListKopegDaoImpl() {
        super(ListKopeg.class);
    }

	public boolean checkInListKopeg (String username, String password) {
		Criteria criteria = getCurrentSession().createCriteria(ListKopeg.class);
    	criteria.add(Restrictions.eq("kodeKopeg", username)); 
    	criteria.add(Restrictions.eq("password", password)); 
    	
    	List<ListKopeg> list = criteria.list();
    	
    	if (list.size() == 0) {
    		return false;
    	}
    	else {
    		if (list.size() == 1) {
    			return true;
    		}
    	}
        return false;
	}
	
	public boolean checkInListKopeg (String username) {
		Criteria criteria = getCurrentSession().createCriteria(ListKopeg.class);
    	criteria.add(Restrictions.eq("kodeKopeg", username)); 
    	
    	List<ListKopeg> list = criteria.list();
    	
    	if (list.size() == 0) {
    		return false;
    	}
    	else {
    		if (list.size() == 1) {
    			return true;
    		}
    	}
        return false;
	}
	
	public ListKopeg resetPasswordKopeg (String username) {
		Criteria criteria = getCurrentSession().createCriteria(ListKopeg.class);
    	criteria.add(Restrictions.eq("kodeKopeg", username));
    	
    	List<ListKopeg> list = criteria.list();
        return list.get(0);
	}
	
	public ListKopeg changePasswordKopeg (String username, String password) {
		Criteria criteria = getCurrentSession().createCriteria(ListKopeg.class);
    	criteria.add(Restrictions.eq("kodeKopeg", username));
    	
    	List<ListKopeg> list = criteria.list();
        return list.get(0);
	}
	
	public String getKodeKopeg (String namaKopeg) {
		Criteria criteria = getCurrentSession().createCriteria(ListKopeg.class);
    	criteria.add(Restrictions.eq("namaKopeg", namaKopeg)); 
    	
    	List<ListKopeg> list = criteria.list();
        return list.get(0).getKodeKopeg() ;
	}
	
	public String getNamaKopeg (String kodeKopeg) {
		Criteria criteria = getCurrentSession().createCriteria(ListKopeg.class);
    	criteria.add(Restrictions.eq("kodeKopeg", kodeKopeg)); 
    	
    	List<ListKopeg> list = criteria.list();
        return list.get(0).getNamaKopeg() ;
	}
	
	public int getId (String kodeKopeg) {
		
		Criteria criteria = getCurrentSession().createCriteria(ListKopeg.class);
    	criteria.add(Restrictions.eq("kodeKopeg", kodeKopeg)); 
    	
    	List<ListKopeg> list = criteria.list();
        return list.get(0).getId() ;
	}
	
	public String getKodeKopegss (int id) {
		Criteria criteria = getCurrentSession().createCriteria(ListKopeg.class);
    	criteria.add(Restrictions.eq("id", id)); 
    	
    	List<ListKopeg> list = criteria.list();
        return list.get(0).getKodeKopeg() ;
	}
	
	public int getTotalKopeg () {
		
		Criteria criteria = getCurrentSession().createCriteria(ListKopeg.class);
    	criteria.add(Restrictions.isNotNull("kodeKopeg")); 
    	
    	List<ListKopeg> list = criteria.list();
        return list.size() ;
	}
	
    public List<ListKopeg> getAllListKopeg() {
      	
    	Criteria criteria = getCurrentSession().createCriteria(ListKopeg.class);
    	criteria.add(Restrictions.isNotNull("kodeKopeg"));
    	List<ListKopeg> listKopeg = criteria.list();
    	    	
    	return listKopeg;
	}
	
}
